<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/1/7
 * Time: 9:39
 */
namespace app\api\controller;
use think\Db;
use Qiniu\Auth;
class Vip extends Base {
      //背景图片
      public function banner(){
          $res =  Db::table('up_backdrop')->where('backdrop_status',3)->find();
          return json(['status' => 200, 'msg' => $res]);
      }
      //猜你在追
      public function index(){
          $res = Db::table('up_video')->alias('a')
              ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
              ->orderRaw('rand()')
              ->where('is_vip',2)
              ->where('is_type',1)
              ->limit(10)
              ->field('a.*,uvm.video_modular_name')
              ->select();
          return json(['status' => 200, 'msg' => $res]);
      }

      //猜你在追更多
    public function moreIndex(){
        $page = input('param.page')?input('param.page'):1;
        $year = input('param.year');//年份
        $school = input('param.school');//流派
        $modular = input('param.modular');//剧种
        $type = input('param.type');//1从低到高   2从高到低
        $where = array();
        if($year!=''){
            $where['a.video_year'] = $year;
        }
        if($school!=''){
            $where['a.video_lp_id'] = $school;
        }
        if($modular!=''){
            $where['a.video_f_id'] = $modular;
        }
        if($type!=''){
            if($type==1){
                $order = 'a.video_num asc';
            }elseif($type==2){
                $order = 'a.video_num desc';
            }
        }else{
            $order = 'a.video_num desc';
        }

        $num = 9;
        $limit = $page-1;
        $res = Db::table('up_video')->alias('a')
            ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
            ->where('is_vip',2)
            ->where('is_type',1)
            ->where($where)
            ->limit($limit*$num,$num)
            ->field('a.*,uvm.video_modular_name')
            ->order($order)
            ->select();
        return json(['status' => 200, 'msg' => $res]);
    }
        //今日今选
     public function today(){
         $res = Db::table('up_video')->alias('a')
             ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
             ->orderRaw('rand()')
             ->where('video_jrjx',1)
             ->where('is_type',1)
             ->where('is_vip',2)
             ->limit(4)
             ->field('a.*,uvm.video_modular_name')
             ->select();
         return json(['status' => 200, 'msg' => $res]);
     }
     //今日今选更多
    public function moreToday(){
        $page = input('param.page')?input('param.page'):1;
        $year = input('param.year');//年份
        $school = input('param.school');//流派
        $modular = input('param.modular');//剧种
        $type = input('param.type');//1从低到高   2从高到低
        $where = array();
        if($year!=''){
            $where['a.video_year'] = $year;
        }
        if($school!=''){
            $where['a.video_lp_id'] = $school;
        }
        if($modular!=''){
            $where['a.video_f_id'] = $modular;
        }
        if($type!=''){
            if($type==1){
                $order = 'a.video_num asc';
            }elseif($type==2){
                $order = 'a.video_num desc';
            }
        }else{
            $order = 'a.video_num desc';
        }
        $num = 9;
        $limit = $page-1;
        $res = Db::table('up_video')->alias('a')
            ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
            ->where('video_jrjx',1)
            ->limit($limit*$num,$num)
            ->where($where)
            ->where('is_type',1)
            ->where('is_vip',2)
            ->order($order)
            ->field('a.*,uvm.video_modular_name')
            ->select();
        return json(['status' => 200, 'msg' => $res]);
    }
    //推荐VIP
    public function vip(){
        $res = Db::table('up_video')->alias('a')
            ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
            ->orderRaw('rand()')
//            ->where('is_exclusive',1)
            ->where('is_type',1)
            ->where('is_vip',2)
            ->limit(3)
            ->field('a.*,uvm.video_modular_name')
            ->select();
        return json(['status' => 200, 'msg' => $res]);
    }
    //推荐到Vip更多
    public function moreVip(){
        $page = input('param.page')?input('param.page'):1;
        $year = input('param.year');//年份
        $school = input('param.school');//流派
        $modular = input('param.modular');//剧种
        $type = input('param.type');//1从低到高   2从高到低
        $where = array();
        if($year!=''){
            $where['a.video_year'] = $year;
        }
        if($school!=''){
            $where['a.video_lp_id'] = $school;
        }
        if($modular!=''){
            $where['a.video_f_id'] = $modular;
        }
        if($type!=''){
            if($type==1){
                $order = 'a.video_num asc';
            }elseif($type==2){
                $order = 'a.video_num desc';
            }
        }else{
            $order = 'a.video_num desc';
        }
        $num = 9;
        $limit = $page-1;
        $res = Db::table('up_video')->alias('a')
            ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
//            ->where('is_exclusive',1)
            ->where('is_type',1)
            ->where('is_vip',2)
            ->where($where)
            ->order($order)
            ->limit($limit*$num,$num)
            ->field('a.*,uvm.video_modular_name')
            ->select();
        return json(['status' => 200, 'msg' => $res]);
    }


//    public function moreVipAll(){
//        $page = input('param.page')?input('param.page'):1;
//        $year = input('param.year');//年份
//        $school = input('param.school');//流派
//        $modular = input('param.modular');//剧种
//        $type = input('param.type');//1从低到高   2从高到低
//        $where = array();
//        if($year!=''){
//            $where['a.video_year'] = $year;
//        }
//        if($school!=''){
//            $where['a.video_lp_id'] = $school;
//        }
//        if($modular!=''){
//            $where['a.video_f_id'] = $modular;
//        }
//        if($type!=''){
//            if($type==1){
//                $order = 'a.video_num asc';
//            }elseif($type==2){
//                $order = 'a.video_num desc';
//            }
//        }else{
//            $order = 'a.video_num desc';
//        }
//        $num = 10;
//        $limit = $page-1;
//        $res = Db::table('up_video')->alias('a')
//            ->join('up_video_modular uvm','uvm.video_modular_id = a.video_f_id','left')
//            ->where('is_vip',2)
//            ->where('is_type',1)
//            ->where($where)
//            ->order($order)
//            ->limit($limit*$num,$num)
//            ->field('a.*,uvm.video_modular_name')
//            ->select();
//        return json(['status' => 200, 'msg' => $res]);
//    }
    /**
     * 获取七牛token
     * @return string
     */
    public function getQiniuToken(){
        require_once ('../extend/qiniu/autoload.php');
        header("Access-Control-Allow-Origin:*");
        $accessKey = config('qiniu')['accessKey'];
        $secretKey = config('qiniu')['secretKey'];
        $bucket = config('qiniu')['bucket'];
        $auth = new Auth($accessKey, $secretKey);
        $token = $auth->uploadToken($bucket);
        return json_encode(array('data'=>$token));
    }

}